// export default usePersonHouseData;
import {reactive, onMounted, onUnmounted} from "vue";
import liaoning from "@/utils/liaoning.json";

const usePersonHouseData = (): any => {
  // 数据部分
  const personHouseData = reactive<any>({
    // 个人拥有住房增长趋势-个人拥有住房数量和同比增长率统计
    personHouseStatisticsData: {},
    personHouseStatisticsDataLast: {},
    personHouseStatisticsSelectModel: 1, // 个人拥有住房增长趋势-select
    personHouseStatisticsSelectList: [ // 个人拥有住房增长趋势-select-list
      {
        label: '户型',
        value: 1
      },
      {
        label: '面积',
        value: 2
      },
      {
        label: '地区',
        value: 3
      },
    ],
    // 个人拥有住房增长趋势-个人拥有住房户型和面积分类统计
    personHouseTypeStatisticsData: {},
    // 个人拥有住房属性占比及趋势
    zbInd: 0,
    componentNum: 1,
    magnifyData: {
      dialogVisible: false,
      componentName: '',
      componentParams: {},
      dialogWidth: '',
      props: {},
      dialogTop: '',
      moduleName: ''
    },
    personHousePropertyStatisticsData: {},
    personHousePropertyStatisticsData1: {},
    personHousePropertyStatisticsData2: {},
    personHousePropertyStatisticsSelectTypeModel: '房屋性质', // 个人拥有住房属性占比及趋势-类型-select-model
    personHousePropertyStatisticsSelectAcreageModel: '全部面积', // 个人拥有住房属性占比及趋势-面积-select-model
    personHousePropertyStatisticsSelectHouseTypeModel: '全部户型', // 个人拥有住房属性占比及趋势-户型-select-model
    personHouseSupplyTradeTrendSelectAcreageModel: '全部面积', // 个人住房供应与交易趋势-面积-select-model
    personHouseSupplyTradeTrendSelectHouseTypeModel: '全部户型', // 个人住房供应与交易趋势-户型-select-model
    personHousePropertyStatisticsSelectTypeList: [ // 个人拥有住房属性占比及趋势-select-list
      {
        label: '房屋性质',
        value: '房屋性质'
      },
      {
        label: '房屋权利限制',
        value: '房屋权利限制'
      },
      {
        label: '产权结构',
        value: '产权结构'
      },
    ],
    personHousePropertyStatisticsSelectAcreageList: [ // 个人拥有住房属性占比及趋势-面积-select-list
      {
        label: '全部面积',
        value: '全部面积'
      },
      {
        label: '60平以下',
        value: '60平以下'
      },
      {
        label: '60-90平',
        value: '60-90平'
      },
      {
        label: '120-144平',
        value: '120-144平'
      },
      {
        label: '144-180平',
        value: '144-180平'
      },
      {
        label: '180平以上',
        value: '180平以上'
      },
    ],
    personHousePropertyStatisticsSelectHouseTypeList: [ // 个人拥有住房属性占比及趋势-户型-select-list
      {
        label: '全部户型',
        value: '全部户型'
      },
      {
        label: '一居室',
        value: '一居室'
      },
      {
        label: '二居室',
        value: '二居室'
      },
      {
        label: '三居室',
        value: '三居室'
      },
      {
        label: '四居室',
        value: '四居室'
      },
      {
        label: '五居室',
        value: '五居室'
      },
    ],
    // 个人拥有住房购房资金来源及贷款趋势
    personHouseFundStatisticsData: {},
    personHouseCapitalSourceCurrentMonth: '', // 购房资金来源统计-单月筛选
    // 个人住房面积走势分析
    personHouseAreaData: {},
    // 个人拥有房屋数量统计
    personHouseNumberData: {},
    // 个人住房供应与交易趋势左侧
    personHouseSupplyData: {},
    // 个人住房供应与交易趋势右侧
    personHouseSupplyRigthData1: {},
    personHouseSupplyRigthData2: {},
    // 个人住房供应与交易趋势右侧轮播索引
    carouselInd: 0,
    // 商品房总量变化分析
    personHouseCommodityData: {},
    // 常住人口对个人住房的影响左侧
    personHousePopulationData: {},
    // 常住人口对个人住房的影响右侧
    personHousePopulationRightData: {},
    buyerPurchaseStatisticsSelectHouseTypeModel: '商品房', // 购房人购房情况统计-房屋类型筛选model
    personHousePropertyStatisticsSelectAgeHomeModel: 1, // 购房人购房情况统计-户籍年龄筛选model
    buyerPurchaseStatisticsSelectHouseTypeList: [ // 购房人购房情况统计-房屋类型筛选list
      {
        label: '商品房',
        value: '商品房'
      },
      {
        label: '商品住宅',
        value: '商品住宅'
      },
      {
        label: '二手房',
        value: '二手房'
      }
    ],
    buyerPurchaseStatisticsSelectAgeHomeList: [ // 购房人购房情况统计-年龄户籍筛选list
      {
        label: '按年龄',
        value: 1
      },
      {
        label: '户籍',
        value: 2
      }
    ],
    buyerPurchaseStatisticsData: {
      xAxisTimeType: 'year'
    }, // 购房人购房情况统计
    // 中间地图
    personHouseMiddleData: {},
    // 中间列表
    personHouseMiddleListData: {},
    // 地图标签数据  标签索引
    mapLable: ["供应", "库存", "销量", "单价"],
    mapInd: 0,
    timeList: ["本年", "近三年", "自定义"],
    timeInd: 1,
    value1: "",
    value2: "",
    cityName: "",
    paramsApi: {
      adcode: localStorage.getItem("cityCode"),
      dateType: 3,
      startTime: "",
      endTime: "",
    },
    dialogVisible: false,
    componentName: "",
    componentParams: {},
    cityList: [
      {name: '沈阳市', code: '210100', select: {disabled: false}},
      {name: '大连市', code: '210200', select: {disabled: false}},
      {name: '鞍山市', code: '210300', select: {disabled: false}},
      {name: '抚顺市', code: '210400', select: {disabled: false}},
      {name: '本溪市', code: '210500', select: {disabled: false}},
      {name: '丹东市', code: '210600', select: {disabled: false}},
      {name: '锦州市', code: '210700', select: {disabled: false}},
      {name: '营口市', code: '210800', select: {disabled: false}},
      {name: '阜新市', code: '210900', select: {disabled: false}},
      {name: '辽阳市', code: '211000', select: {disabled: false}},
      {name: '盘锦市', code: '211100', select: {disabled: false}},
      {name: '铁岭市', code: '211200', select: {disabled: false}},
      {name: '朝阳市', code: '211300', select: {disabled: false}},
      {name: '葫芦岛市', code: '211400', select: {disabled: false}},
    ],
    cityConfig: {
      personHouseAttributeProportionTrendCurrentCity: localStorage.getItem("cityCode"), // 个人拥有住房属性占比及趋势-城市code
      personHouseCapitalSourceLoanTrendCurrentCity: localStorage.getItem("cityCode"), // 个人拥有住房购房资金来源及贷款趋势-城市code
      personHouseSupplyTradeTrendCurrentCity: localStorage.getItem("cityCode"), // 个人住房供应与交易趋势-城市code
      totalHouseChangeAnalysisCurrentCity: localStorage.getItem("cityCode"), // 房屋总量变化分析-城市code
      buyerPurchaseStatisticsCurrentCity: localStorage.getItem("cityCode"), // 购房人购房情况统计-城市code
    },
    regionRankingCurrentYear: '', // 各地区排名单年筛选model
    regionRankingList: [], // 各地区排名list
    houseSituationStatisticsSwitch: true, // 个人拥有房屋情况统计-且或switch切换
    houseSituationStatisticsFiltrateList: [
      {
        type: 1,
        relationalOperatorType: 3,
        num: null
      }
    ], // 个人拥有房屋情况统计-筛选data-list
    houseSituationStatisticsFiltrateSelectTypeList: [
      {
        label: '现持有房屋数量',
        value: 1,
        disabled: true
      },
      {
        label: '累计购房次数',
        value: 2,
        disabled: false
      },
      {
        label: '累计售房次数',
        value: 3,
        disabled: false
      },
      {
        label: '平均买房周期',
        value: 4,
        disabled: false
      }
    ], // 个人拥有房屋情况统计-筛选-type-select-list
    houseSituationStatisticsFiltrateSelectRelationalOperatorList: [
      {
        label: '小于',
        value: 1
      },
      {
        label: '大于',
        value: 2
      },
      {
        label: '等于',
        value: 3
      },
    ], // 个人拥有房屋情况统计-筛选-关系运算符-select-list
  });
  let arr = liaoning.features.find((item: any) => item.properties.adcode == localStorage.getItem("cityCode"));
  personHouseData.cityName = arr?.properties.name || "";
  // 生命周期钩子
  const startTimer = () => {
    let timer: any;
    onMounted(() => {
      timer = setInterval(() => {
        personHouseData.mapInd = (personHouseData.mapInd + 1) % 4;
      }, 20000);
    });

    onUnmounted(() => {
      clearInterval(timer);
    });
  };

  startTimer(); // 启动定时器
  return personHouseData;
};

export default usePersonHouseData;
